package mapper

import (
	"gin-epg/internal/app/dao"
	"gin-epg/internal/app/entity"
	"gin-epg/internal/app/param"
)

/*
*
获取epgChannel集合
*/
func GetToolMulticastPlatformList(params *param.QueryToolMulticastPlatformParam) (toolMulticastPlatformList []*entity.ToolMulticastPlatform, err error) {
	query := dao.SqlSession.Model(&entity.ToolMulticastPlatform{})

	if params.Platform != "" {
		query = query.Where("platform LIKE ?", "%"+params.Platform+"%")
	}

	if params.Province != "" {
		query = query.Where("province LIKE ?", "%"+params.Province+"%")
	}

	if params.City != "" {
		query = query.Where("city LIKE ?", "%"+params.City+"%")
	}

	if params.Operator != "" {
		query = query.Where("operator LIKE ?", "%"+params.Operator+"%")
	}

	if err := query.Find(&toolMulticastPlatformList).Error; err != nil {
		return nil, err
	}
	return
}

// CreateToolMulticastPlatform 创建一个新的 ToolMulticastPlatform
func CreateToolMulticastPlatform(toolMulticastPlatform *entity.ToolMulticastPlatform) (err error) {
	if err = dao.SqlSession.Create(toolMulticastPlatform).Error; err != nil {
		return err
	}
	return
}

/*
* 获取 ToolMulticastPlatform 集合
 */
func GetAllToolMulticastPlatform() (toolMulticastPlatformList []*entity.ToolMulticastPlatform, err error) {
	if err := dao.SqlSession.Find(&toolMulticastPlatformList).Error; err != nil {
		return nil, err
	}
	return
}

/*
* 根据 id 删除 ToolMulticastPlatform
 */
func DeleteToolMulticastPlatformById(id string) (err error) {
	err = dao.SqlSession.Where("id=?", id).Delete(&entity.ToolMulticastPlatform{}).Error
	return
}

/*
* 根据 id 查询 ToolMulticastPlatform
 */
func GetToolMulticastPlatformById(id string) (toolMulticastPlatform *entity.ToolMulticastPlatform, err error) {
	// 初始化 toolMulticastPlatform 变量
	toolMulticastPlatform = new(entity.ToolMulticastPlatform)

	// 执行查询
	if err = dao.SqlSession.Where("id=?", id).First(toolMulticastPlatform).Error; err != nil {
		return nil, err
	}
	return toolMulticastPlatform, nil
}

/*
* 更新 ToolMulticastPlatform 信息
 */
func UpdateToolMulticastPlatform(toolMulticastPlatform *entity.ToolMulticastPlatform) (err error) {
	err = dao.SqlSession.Save(toolMulticastPlatform).Error
	return
}
